home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / src / out-of-phase-102-c / OutOfPhase 1.02 Source / OutOfPhase Folder / DrawCommand.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-23  |  8.9 KB  |  275 lines  |  [TEXT/KAHL]

  1. /* DrawCommand.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    Out Of Phase:  Digital Music Synthesis on General Purpose Computers    */
  5. /*    Copyright (C) 1994  Thomas R. Lawrence                                 */
  6. /*                                                                           */
  7. /*    This program is free software; you can redistribute it and/or modify   */
  8. /*    it under the terms of the GNU General Public License as published by   */
  9. /*    the Free Software Foundation; either version 2 of the License, or      */
  10. /*    (at your option) any later version.                                    */
  11. /*                                                                           */
  12. /*    This program is distributed in the hope that it will be useful,        */
  13. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  14. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          */
  15. /*    GNU General Public License for more details.                           */
  16. /*                                                                           */
  17. /*    You should have received a copy of the GNU General Public License      */
  18. /*    along with this program; if not, write to the Free Software            */
  19. /*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              */
  20. /*                                                                           */
  21. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24.  
  25. #include "MiscInfo.h"
  26. #include "Audit.h"
  27. #include "Debug.h"
  28. #include "Definitions.h"
  29.  
  30. #include "DrawCommand.h"
  31. #include "DataMunging.h"
  32. #include "Memory.h"
  33.  
  34.  
  35. #define BORDER (3)
  36.  
  37.  
  38. /* draw a command with no parameters.  the string is null terminated */
  39. OrdType                        DrawCommandNoParams(WinType* Window, OrdType X, OrdType Y,
  40.                                         FontType Font, FontSizeType FontSize, MyBoolean ActuallyDraw,
  41.                                         MyBoolean GreyedOut, char* String)
  42.     {
  43.         OrdType                    StrWidth;
  44.         long                        StrLength;
  45.  
  46.         ERROR(String == NIL,PRERR(ForceAbort,"DrawCommandNoParams:  NIL string"));
  47.         StrLength = StrLen(String);
  48.         StrWidth = LengthOfText(Font,FontSize,String,StrLength,ePlain);
  49.         if (ActuallyDraw)
  50.             {
  51.                 OrdType                    FontHeight;
  52.  
  53.                 FontHeight = GetFontHeight(Font,FontSize);
  54.                 DrawBoxFrame(Window,eBlack,X,Y,StrWidth + 2 * BORDER,FontHeight + 2 * BORDER);
  55.                 DrawBoxErase(Window,X + 1,Y + 1,StrWidth + 2 * BORDER - 1 - 1,
  56.                     FontHeight + 2 * BORDER - 1 - 1);
  57.                 DrawTextLine(Window,Font,FontSize,String,StrLength,X + BORDER,Y + BORDER,ePlain);
  58.             }
  59.         return StrWidth + 2 * BORDER;
  60.     }
  61.  
  62.  
  63. /* draw a command with one parameter.  first string is null terminated and not */
  64. /* disposed, but the second string is a non-null-terminated heap block which is */
  65. /* disposed.  if the second one is NIL, then it is ignored */
  66. OrdType                        DrawCommand1Param(WinType* Window, OrdType X, OrdType Y,
  67.                                         FontType Font, FontSizeType FontSize, MyBoolean ActuallyDraw,
  68.                                         MyBoolean GreyedOut, char* String, char* Argument1)
  69.     {
  70.         OrdType                    TotalWidth;
  71.         long                        FirstLength;
  72.         long                        SecondLength;
  73.  
  74.         ERROR(String == NIL,PRERR(ForceAbort,"DrawCommand1Param:  NIL string"));
  75.         FirstLength = StrLen(String);
  76.         TotalWidth = LengthOfText(Font,FontSize,String,FirstLength,ePlain);
  77.         if (Argument1 != NIL)
  78.             {
  79.                 OrdType                    OtherWidth;
  80.  
  81.                 SecondLength = PtrSize(Argument1);
  82.                 OtherWidth = LengthOfText(Font,FontSize,Argument1,SecondLength,ePlain);
  83.                 if (OtherWidth > TotalWidth)
  84.                     {
  85.                         TotalWidth = OtherWidth;
  86.                     }
  87.             }
  88.         if (ActuallyDraw)
  89.             {
  90.                 OrdType                    FontHeight;
  91.  
  92.                 FontHeight = GetFontHeight(Font,FontSize);
  93.                 DrawBoxFrame(Window,eBlack,X,Y,TotalWidth + 2 * BORDER,
  94.                     2 * FontHeight + 2 * BORDER);
  95.                 DrawBoxErase(Window,X + 1,Y + 1,TotalWidth + 2 * BORDER - 1 - 1,
  96.                     2 * FontHeight + 2 * BORDER - 1 - 1);
  97.                 DrawTextLine(Window,Font,FontSize,String,FirstLength,
  98.                     X + BORDER,Y + BORDER,ePlain);
  99.                 if (Argument1 != NIL)
  100.                     {
  101.                         DrawTextLine(Window,Font,FontSize,Argument1,SecondLength,X + BORDER,
  102.                             Y + BORDER + FontHeight,ePlain);
  103.                     }
  104.             }
  105.         if (Argument1 != NIL)
  106.             {
  107.                 ReleasePtr(Argument1);
  108.             }
  109.         return TotalWidth + 2 * BORDER;
  110.     }
  111.  
  112.  
  113. /* draw a command with 2 parameters */
  114. OrdType                        DrawCommand2Params(WinType* Window, OrdType X, OrdType Y,
  115.                                         FontType Font, FontSizeType FontSize, MyBoolean ActuallyDraw,
  116.                                         MyBoolean GreyedOut, char* String, char* Argument1,
  117.                                         char* Argument2)
  118.     {
  119.         OrdType                    TotalWidth;
  120.         long                        FirstLength;
  121.         long                        SecondLength;
  122.         long                        ThirdLength;
  123.  
  124.         ERROR(String == NIL,PRERR(ForceAbort,"DrawCommand2Params:  NIL string"));
  125.         FirstLength = StrLen(String);
  126.         TotalWidth = LengthOfText(Font,FontSize,String,FirstLength,ePlain);
  127.         if (Argument1 != NIL)
  128.             {
  129.                 OrdType                    OtherWidth;
  130.  
  131.                 SecondLength = PtrSize(Argument1);
  132.                 OtherWidth = LengthOfText(Font,FontSize,Argument1,SecondLength,ePlain);
  133.                 if (OtherWidth > TotalWidth)
  134.                     {
  135.                         TotalWidth = OtherWidth;
  136.                     }
  137.             }
  138.         if (Argument2 != NIL)
  139.             {
  140.                 OrdType                    OtherWidth;
  141.  
  142.                 ThirdLength = PtrSize(Argument2);
  143.                 OtherWidth = LengthOfText(Font,FontSize,Argument2,ThirdLength,ePlain);
  144.                 if (OtherWidth > TotalWidth)
  145.                     {
  146.                         TotalWidth = OtherWidth;
  147.                     }
  148.             }
  149.         if (ActuallyDraw)
  150.             {
  151.                 OrdType                    FontHeight;
  152.  
  153.                 FontHeight = GetFontHeight(Font,FontSize);
  154.                 DrawBoxFrame(Window,eBlack,X,Y,TotalWidth + 2 * BORDER,
  155.                     3 * FontHeight + 2 * BORDER);
  156.                 DrawBoxErase(Window,X + 1,Y + 1,TotalWidth + 2 * BORDER - 1 - 1,
  157.                     3 * FontHeight + 2 * BORDER - 1 - 1);
  158.                 DrawTextLine(Window,Font,FontSize,String,FirstLength,X + BORDER,
  159.                     Y + BORDER,ePlain);
  160.                 if (Argument1 != NIL)
  161.                     {
  162.                         DrawTextLine(Window,Font,FontSize,Argument1,SecondLength,X + BORDER,
  163.                             Y + BORDER + FontHeight,ePlain);
  164.                     }
  165.                 if (Argument2 != NIL)
  166.                     {
  167.                         DrawTextLine(Window,Font,FontSize,Argument2,ThirdLength,X + BORDER,
  168.                             Y + BORDER + 2 * FontHeight,ePlain);
  169.                     }
  170.             }
  171.         if (Argument1 != NIL)
  172.             {
  173.                 ReleasePtr(Argument1);
  174.             }
  175.         if (Argument2 != NIL)
  176.             {
  177.                 ReleasePtr(Argument2);
  178.             }
  179.         return TotalWidth + 2 * BORDER;
  180.     }
  181.  
  182.  
  183. /* draw a command that has one parameter, but has line feeds in it. */
  184. /* first string is null terminated and not disposed, but the second string is */
  185. /* a non-null-terminated heap block which is disposed.  if the second one is NIL, */
  186. /* then it is ignored */
  187. OrdType                        DrawCommand1ParamWithLineFeeds(WinType* Window, OrdType X, OrdType Y,
  188.                                         FontType Font, FontSizeType FontSize, MyBoolean ActuallyDraw,
  189.                                         MyBoolean GreyedOut, char* String, char* Argument1)
  190.     {
  191.         OrdType                    TotalWidth;
  192.         long                        FirstLength;
  193.         long                        SecondLength;
  194.         long                        NumberOfLines;
  195.  
  196.         ERROR(String == NIL,PRERR(ForceAbort,"DrawCommand1ParamWithLineFeeds:  NIL string"));
  197.         FirstLength = StrLen(String);
  198.         TotalWidth = LengthOfText(Font,FontSize,String,FirstLength,ePlain);
  199.         NumberOfLines = 1;
  200.         if (Argument1 != NIL)
  201.             {
  202.                 long                        CharScan;
  203.  
  204.                 SecondLength = PtrSize(Argument1);
  205.                 CharScan = 0;
  206.                 while (CharScan < SecondLength)
  207.                     {
  208.                         OrdType                    OtherWidth;
  209.                         long                        StartIndex;
  210.  
  211.                         StartIndex = CharScan;
  212.                         while ((Argument1[CharScan] != '\x0d')
  213.                             && (Argument1[CharScan] != '\x0a') && (CharScan < SecondLength))
  214.                             {
  215.                                 CharScan += 1;
  216.                             }
  217.                         OtherWidth = LengthOfText(Font,FontSize,&(Argument1[StartIndex]),
  218.                             CharScan - StartIndex,ePlain);
  219.                         if (OtherWidth > TotalWidth)
  220.                             {
  221.                                 TotalWidth = OtherWidth;
  222.                             }
  223.                         if (CharScan < SecondLength)
  224.                             {
  225.                                 CharScan += 1;
  226.                             }
  227.                         NumberOfLines += 1;
  228.                     }
  229.             }
  230.         if (ActuallyDraw)
  231.             {
  232.                 OrdType                    FontHeight;
  233.  
  234.                 FontHeight = GetFontHeight(Font,FontSize);
  235.                 DrawBoxFrame(Window,eBlack,X,Y,TotalWidth + 2 * BORDER,
  236.                     NumberOfLines * FontHeight + 2 * BORDER);
  237.                 DrawBoxErase(Window,X + 1,Y + 1,TotalWidth + 2 * BORDER - 1 - 1,
  238.                     NumberOfLines * FontHeight + 2 * BORDER - 1 - 1);
  239.                 DrawTextLine(Window,Font,FontSize,String,FirstLength,
  240.                     X + BORDER,Y + BORDER,ePlain);
  241.                 if (Argument1 != NIL)
  242.                     {
  243.                         long                        CharScan;
  244.                         long                        LineCount;
  245.  
  246.                         CharScan = 0;
  247.                         LineCount = 1;
  248.                         while (CharScan < SecondLength)
  249.                             {
  250.                                 long                        StartIndex;
  251.  
  252.                                 StartIndex = CharScan;
  253.                                 while ((Argument1[CharScan] != '\x0d')
  254.                                     && (Argument1[CharScan] != '\x0a') && (CharScan < SecondLength))
  255.                                     {
  256.                                         CharScan += 1;
  257.                                     }
  258.                                 DrawTextLine(Window,Font,FontSize,&(Argument1[StartIndex]),
  259.                                     CharScan - StartIndex,X + BORDER,Y + BORDER + FontHeight * LineCount,
  260.                                     ePlain);
  261.                                 if (CharScan < SecondLength)
  262.                                     {
  263.                                         CharScan += 1;
  264.                                     }
  265.                                 LineCount += 1;
  266.                             }
  267.                     }
  268.             }
  269.         if (Argument1 != NIL)
  270.             {
  271.                 ReleasePtr(Argument1);
  272.             }
  273.         return TotalWidth + 2 * BORDER;
  274.     }
  275.